package com.cx.controller.admin.basic;

import com.cx.service.RedisService;
import com.cx.service.admin.basic.ChainBasicPrivilegeManager;
import com.cx.service.admin.basic.ChainBasicRoleManager;
import com.cx.utils.RedisKeyUtil;
import org.cx.base.ApiModel;
import org.cx.base.BaseController;
import org.cx.constant.ServerCodeType;
import org.cx.entity.Page;
import org.cx.entity.PageData;
import org.cx.util.AssertUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@RestController("admin/basic/role")
@RequestMapping("admin/basic/role")
public class RoleController extends BaseController {

    @Resource
    private ChainBasicRoleManager chainBasicRoleService;

    @Resource
    private RedisService jedisService;


    @ResponseBody
    @RequestMapping(value = "/findPrivilegeDetailPage")
    public ApiModel findroleDetailPage() throws Exception {
        Page pg =this.getPage();
        List<PageData> list = chainBasicRoleService.findRoleDetailPage(pg);
        pg.setPd(list);
        return buildSuccMsg(pg);
    }

    @ResponseBody
    @RequestMapping(value = "/findRoleByPageDate")
    public ApiModel findRoleByPageDate(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        PageData pd =this.getPageData();
        String token = req.getHeader("token");
        pd.put("orgId",jedisService.getSession(RedisKeyUtil.getLoginUserKey(token)).get("orgId"));
        List<PageData> list = chainBasicRoleService.findRoleByPageDate(pd);
        return buildSuccMsg(pd);
    }

    @ResponseBody
    @RequestMapping(value = "/findRoleForChoseRole")
    public ApiModel findRoleForChoseRole(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        PageData pd =this.getPageData();
        String token = req.getHeader("token");
        pd.put("orgId",jedisService.getSession(RedisKeyUtil.getLoginUserKey(token)).get("orgId"));
        List<PageData> list =  chainBasicRoleService.findRoleForChoseRoleNotClerk(pd);
        return buildSuccMsg(list);
    }

    @ResponseBody
    @RequestMapping(value = "/selectRoleByID")
    public ApiModel selectRoleByID() throws Exception {
        PageData pd =this.getPageData();
        pd = chainBasicRoleService.selectRoleByID(pd);
        //   pg.setPd(list);
        return buildSuccMsg(pd);
    }

    @ResponseBody
    @RequestMapping(value = "/updateRole")
    public ApiModel updateRole() throws Exception {
        PageData pd =this.getPageData();
        Integer result = chainBasicRoleService.updateRole(pd);
        //   pg.setPd(list);
        return buildSuccMsg(pd);
    }

    @ResponseBody
    @RequestMapping(value = "/insertRole")
    public ApiModel insertRole() throws Exception {
        PageData pd =this.getPageData();
        Integer result  = chainBasicRoleService.insertRole(pd);
        //   pg.setPd(list);
        return buildSuccMsg(pd);
    }


}
